using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public static class TransporterUtil 
{
    public static void UploadAllFilesInDir(Transporter client, string fromLocalPath, string filePatterm, string toRemotePath, bool canOverride)
    {
        Debug.Log(" syncDir: " + fromLocalPath + " -> " + toRemotePath);
        var filsList = Directory.GetFiles(fromLocalPath, filePatterm, SearchOption.AllDirectories);
        foreach (var localPath in filsList)
        {
            var remotePath = localPath.Replace(fromLocalPath, toRemotePath);

            remotePath = remotePath.Replace("\\", "/");
            if (!canOverride)
            {
                if (client.Exists(remotePath))
                {
                    Debug.Log("file: " + localPath + "    (skip)");
                    continue;
                }
            }

            var fileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read);
            client.WriteFile(fileStream, remotePath, true);
            Debug.Log("file: " + localPath + "    (uploaded)");
            fileStream.Close();
        }
    }
}
